<template>
  <div>
    <div style="margin-left: 5%; margin-top: 1%" align="center">
      <!-- 年级选择-->
      <el-select v-model="grade" placeholder="请选择年级">
        <el-option
          v-for="item in options"
          :key="item.grade"
          :label="item.label"
          :value="item.grade"
          @click="selectByInfo"
        >
        </el-option>
      </el-select>
      <!-- 班级选择-->
      <el-select v-model="clsname" placeholder="请选择班级">
        <el-option
          v-for="item in optionss"
          :key="item.clsname"
          :label="item.label"
          :value="item.clsname"
          @click="selectByInfo"
        >
        </el-option>
      </el-select>
      <el-button
        icon="el-icon-search"
        size="model"
        type="primary"
        @click="selectByInfo"
      >
        搜索
      </el-button>
    </div>
    <div>
      <!-- 年级选择-->
      <el-select v-model="grade" placeholder="请选择年级">
        <el-option
          v-for="item in options"
          :key="item.grade"
          :label="item.label"
          :value="item.grade"
        >
        </el-option>
      </el-select>
      <!-- 班级选择-->
      <el-select v-model="clsname" placeholder="请选择班级">
        <el-option
          v-for="item in optionss"
          :key="item.clsname"
          :label="item.label"
          :value="item.clsname"
        >
        </el-option>
      </el-select>
      <!-- 科目选择-->
      <el-select v-model="type" placeholder="请选择科目">
        <el-option
          v-for="item in options02"
          :key="item.type"
          :label="item.label"
          :value="item.type"
        >
        </el-option>
      </el-select>
      <!-- 教师选择-->
      <el-select
        v-model="name"
        placeholder="请选择教师"
      >
        <el-option
          v-for="item in options03"
          :key="item.name"
          :label="item.name"
          :value="item.name"
        >
        </el-option>
      </el-select>

      <!-- 添加按钮 -->
      <el-button
        icon="el-icon-arragement"
        size="small"
        type="primary"
        @click="arrageTeacher"
      >
        安排教师
      </el-button>
    </div>
    <el-table :data="tableData" style="width: 100%" align="center">
      <el-table-column label="班级名称" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.cname }}</span>
        </template>
      </el-table-column>

      <el-table-column label="科目" width="150">
        <template slot-scope="scope">
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.subject }}</el-tag>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="代课老师" width="150">
        <template slot-scope="scope">
          <div
            slot="reference"
            class="name-wrapper"
            v-if="scope.row.name != null"
          >
            <el-tag size="medium">
              {{ scope.row.name }}
            </el-tag>
          </div>
          <div slot="reference" class="name-wrapper" v-else>
            <el-tag size="medium"> 暂未分配 </el-tag>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="班主任" width="150">
        <template slot-scope="scope">
          <div
            slot="reference"
            class="name-wrapper"
            v-if="scope.row.headTeacher != null"
          >
            <el-tag size="medium">
              {{ scope.row.headTeacher }}
            </el-tag>
          </div>
          <div slot="reference" class="name-wrapper" v-else>
            <el-tag size="medium"> 暂未分配 </el-tag>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="文理分科" width="150">
        <template slot-scope="scope">
          <div
            slot="reference"
            class="name-wrapper"
            v-if="scope.row.status == 0"
          >
            <el-tag size="medium"> 暂未分班 </el-tag>
          </div>
          <div
            slot="reference"
            class="name-wrapper"
            v-if="scope.row.status == 1"
          >
            <el-tag size="medium"> 文科 </el-tag>
          </div>
          <div
            slot="reference"
            class="name-wrapper"
            v-if="scope.row.status == 2"
          >
            <el-tag size="medium"> 理科 </el-tag>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      @next-click="next"
      @prev-click="prev"
      :current-page="currentPage"
      :page-sizes="[8]"
      :page-size="size"
      layout="total, sizes, prev, pager, next"
      :total="total"
      align="center"
    >
    </el-pagination>
  </div>
</template>
<script>
import axios from "axios";
import commons from "../../../assets/commons";
export default {
  data() {
    return {
      currentPage: 1, //当前页
      total: 0, //总条数
      totalPage: 0, //总页数
      page:1,
      size: 8, //每页大小
      tableData: [],

      //选择年级
      options: [
        {
          grade: "高一",
          label: "高一",
        },
        {
          grade: "高二",
          label: "高二",
        },
        {
          grade: "高三",
          label: "高三",
        },
      ],
      grade: "",
      //选择班级
      optionss: [
        {
          clsname: "1班",
          label: "1班",
        },
        {
          clsname: "2班",
          label: "2班",
        },
        {
          clsname: "3班",
          label: "3班",
        },
        {
          clsname: "4班",
          label: "4班",
        },
        {
          clsname: "5班",
          label: "5班",
        },
        {
          clsname: "6班",
          label: "6班",
        },
        {
          clsname: "7班",
          label: "7班",
        },
        {
          clsname: "8班",
          label: "8班",
        },
        {
          clsname: "9班",
          label: "9班",
        },
        {
          clsname: "10班",
          label: "10班",
        },
      ],
      clsname: "",

      options02: [
        {
          type: "1",
          label: "语文",
        },
        {
          type: "2",
          label: "数学",
        },
        {
          type: "3",
          label: "英语",
        },
        {
          type: "4",
          label: "政治",
        },
        {
          type: "5",
          label: "历史",
        },
        {
          type: "6",
          label: "地理",
        },
        {
          type: "7",
          label: "物理",
        },
        {
          type: "8",
          label: "化学",
        },
        {
          type: "9",
          label: "生物",
        },
      ],
      type: "",
      
      options03:[],
      name:"",
    };
  },
  methods: {
    //查询信息
    selectByInfo() {
       
       console.info(this.grade+this.clsname)

      axios
         .get(commons.baseUrl+"gradedean/teacherInfo",
              {params:{page:this.page,size:this.size,
               cname:this.grade+this.clsname}})
         .then(resp=>{

           console.log(resp)

          this.tableData = resp.data.datas;
          this.total = resp.data.total;
          this.totalPage = resp.data.totalPage;
          this.currentPage = resp.data.currentPage;
          this.page = resp.data.currentPage;
          this.size = resp.data.size;
           
         })
    },

    //安排授课教师
    arrageTeacher() {},

    //分页
    findByPage() {
      axios
        .get(
          commons.baseUrl +
            "gradedean/classInfo?page=" +
            this.currentPage +
            "&size=" +
            this.size
        )
        .then((res) => {
          this.tableData = res.data.datas;
          console.log(res);
          this.total = res.data.total;
          this.totalPage = res.data.totalPage;
          this.currentPage = res.data.currentPage;
          this.size = res.data.size;
        });
    },

    //下一页
    next() {
      this.currentPage = this.currentPage + 1;
      axios
        .get(
          commons.baseUrl +
            "gradedean/classInfo?page=" +
            this.currentPage +
            "&size=" +
            this.size
        )
        .then((res) => {
          this.tableData = res.data.datas;
          console.log(res);
          this.total = res.data.total;
          this.totalPage = res.data.totalPage;
          this.currentPage = res.data.currentPage;
          this.size = res.data.size;
        });
    },

    //上一页
    prev() {
      this.currentPage = this.currentPage - 1;
      axios
        .get(
          commons.baseUrl +
            "gradedean/classInfo?page=" +
            this.currentPage +
            "&size=" +
            this.size
        )
        .then((res) => {
          this.tableData = res.data.datas;
          console.log(res);
          this.total = res.data.total;
          this.totalPage = res.data.totalPage;
          this.currentPage = res.data.currentPage;
          this.size = res.data.size;
        });
    },
  },
  mounted() {
    //axios  get请求
    //调用方法获取第一页数据
    this.findByPage();
  },
  computed: {},
};
</script>
<style scoped></style>
